<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

   private $_acl;
   private $_auth;
   
    public function _initAutoloader() {
     $autoloader = new Zend_Loader_Autoloader_Resource(array(
         'basePath' => APPLICATION_PATH,
         'namespace' => '',
         'resourceTypes' => array(
             'form' => array(
                 'namespace' => 'Form',
                 'path' => '/forms'
             ),
            'validator' => array(
                 'namespace' => 'Validate',
                 'path' => '/validators'
            ),
           'model' => array(
                 'namespace' => 'Model',
                 'path' => '/models'
            )
         )
     ));
     $autoloader = Zend_Loader_Autoloader::getInstance();
     $autoloader->registerNamespace('Zgm_');
     
     $this->_acl = new Zgm_Acl(APPLICATION_PATH.'/configs/acl.ini');
     $this->_auth = Zend_Auth::getInstance();
     $fc = Zend_Controller_Front::getInstance();
     $fc->registerPlugin(new Zgm_Controller_Plugin_Acl($this->_acl, $this->_auth));
     $fc->registerPlugin(new Zgm_Controller_Plugin_FlashMessenger());
 }
 
   protected function _initNavigation() {
      $this->bootstrap("layout");
      $layout = $this->getResource('layout');
      $view = $layout->getView();

      $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
      $navigation = new Zend_Navigation($config);
      $view->navigation($navigation);
   }

   /**
    * @todo use for database, at least try
    */
    protected function _initCache(){
      $frontendOptions = array(
         'lifetime' => 7200,
         'automatic_serialization' => true
      );
      $backendOptions = array(
         'cache_dir' => APPLICATION_PATH.'/../public/cache'
      );
       $dbCache = Zend_Cache::factory('Core',
                                      'File',
                                      $frontendOptions,
                                      $backendOptions);

      $manager = new Zend_Cache_Manager;
      $manager->setCache('database', $dbCache);
      Zend_Registry::set('Cache_Manager', $manager);
    }

   protected function _initLog() {
     $logger = new Zend_Log();
     $writer = new Zend_Log_Writer_Firebug();
     $logger->addWriter($writer);
     Zend_Registry::set('logger',$logger);
   }

   protected function _initSession() {
      Zend_Session::start();
   }
}